package com.intelligencesoft.pss.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {

	public static String dateToString(Date date) {
		if (date instanceof Date) {
			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			return sdf.format(date);
		}
		return null;
	}
	
	public static Date stringToDate(String dateStr) {
		if (dateStr instanceof String) {
			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			try {
				return sdf.parse(dateStr);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		return null;
	}
	
	public static long dateToTime(Date date1,Date date2) {
		if (date1!=null&&date2!=null) {
			return date1.getTime()-date2.getTime();
		}
		return 0;
	}
	
}
